import React, { useContext } from 'react';
import { ConfigProvider, Button as AntdButton } from 'antd';
import type { ButtonProps as AntdButtonProps } from 'antd';
import { useButtonStyles } from './style';
import { buttonThemeConfig } from '../../themes/button';

// 导出样式扩展 Hook，方便用户使用特殊效果
export { useButtonStyles } from './style';

export interface ButtonProps extends AntdButtonProps {
  // 继承所有 antd Button 属性，无需额外属性
}

const ButtonComponent: React.FC<ButtonProps> = ({ 
  className,
  ...restProps 
}) => {
  const { styles, cx } = useButtonStyles();
  const context = useContext(ConfigProvider.ConfigContext);
  
  // 合并样式：基础样式 + 用户样式
  const buttonClassName = cx(
    styles.floatingEffect,                   // 基础样式增强
    className                            // 用户自定义样式
  );
   


  return (
    <ConfigProvider
      theme={{
        components: {
          Button: {
            ...buttonThemeConfig,
            ...context?.theme?.components?.Button,
          },
        },
      }}
    >
      <AntdButton 
        className={buttonClassName} 
        {...restProps} 
      />
    </ConfigProvider>
  );
};

const Button = Object.assign(ButtonComponent, {
  Group: AntdButton.Group,
});

export { Button };
export default Button;

